﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class Admin_Components_Report_TransferProductDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string ProductID = Request.QueryString["ProductID"].ToString();
            ViewState["ProductID"] = ProductID;
            string ProvinceIDFrom = Request.QueryString["ProvinceIDFrom"].ToString();
            ViewState["ProvinceIDFrom"] = ProvinceIDFrom;
            string ShopIDFrom = Request.QueryString["ShopIDFrom"].ToString();
            ViewState["ShopIDFrom"] = ShopIDFrom;
            string ProvinceIDTo = Request.QueryString["ProvinceIDTo"].ToString();
            ViewState["ProvinceIDTo"] = ProvinceIDTo;
            string ShopIDTo = Request.QueryString["ShopIDTo"].ToString();
            ViewState["ShopIDTo"] = ShopIDTo;
            string FromDate = Request.QueryString["FromDate"].ToString();
            ViewState["FromDate"] = FromDate;
            string ToDate = Request.QueryString["ToDate"].ToString();
            ViewState["ToDate"] = ToDate;
            loadData();
        }
    }

    private void loadData()
    {
        // gv.CurrentPageIndex = 0;
        DBDataContext db = LINQUtil.GetDBWriteOnly();
        int ProductID = int.Parse(ViewState["ProductID"].ToString());
        int ProvinceIDFrom = int.Parse(ViewState["ProvinceIDFrom"].ToString());
        int ShopIDFrom = int.Parse(ViewState["ShopIDFrom"].ToString());
        int ProvinceIDTo = int.Parse(ViewState["ProvinceIDTo"].ToString());
        int ShopIDTo = int.Parse(ViewState["ShopIDTo"].ToString());
        DateTime FromDate = DateTime.Parse(ViewState["FromDate"].ToString());
        DateTime ToDate = DateTime.Parse(ViewState["ToDate"].ToString());
        int PageNumber = gv.CurrentPageIndex + 1;
        int PageSize = gv.PageSize;
        
        var q = db.Report_TransferProductDetail(ProvinceIDFrom,ShopIDFrom,ProvinceIDTo,ShopIDTo,ProductID,FromDate,ToDate, PageSize, PageNumber).ToList();
        if (q.Count > 0)
        {
            gv.ClientSettings.Scrolling.AllowScroll = true;
            gv.ClientSettings.Scrolling.UseStaticHeaders = true;
            gv.VirtualItemCount = q[0].TotalRows.Value;
            gv.DataSource = q;
        }
        else
        {
            gv.DataSource = new DataTable();
        }

        gv.DataBind();
    }

    protected void gvData_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        loadData();
    }
}